malnut.controller('signUpController',function($scope, $state, $ionicHistory, $ionicPopup, $ionicLoading,$http, sharedData, $cordovaFileTransfer) {
// $scope.data = {};
debugger;
alert($cordovaFileTransfer);
console.log($cordovaFileTransfer);
$scope.newuser={};
$scope.response;
$scope.$on('$ionicView.enter', function(ev) {
    $scope.newuser.fullName="";
    $scope.newuser.userName="";
    $scope.newuser.password="";
    $scope.newuser.email="";
});
//var imageURL = sharedData.getImageURL() + userId + ".jpg";
//document.getElementById("uservAvatar").src= imageURL;
var uploadImageURL = "http://localhost/carvicewebservice/test.php";
console.log(document.getElementById("fileToUpload").value);

var baseURL = sharedData.getLocalURL();
    $scope.newusercrt = function(form){
        debugger;
         $scope.showMsgs = false;
       if (form.$valid) {
           $ionicLoading.show({
            template: '<ion-spinner></ion-spinner><br/>Loading...'
        });
        console.log(document.getElementById("fileToUpload").value);
        alert(document.getElementById("fileToUpload").value);

        console.log(baseURL + "tag=register&fullName="+$scope.newuser.fullName+"&userName="+$scope.newuser.userName+"&password="+$scope.newuser.password+"&email="+$scope.newuser.email+"&address="+$scope.newuser.address);
      // alert(baseURL + "tag=register&fullName="+$scope.newuser.fullName+"&userName="+$scope.newuser.userName+"&password="+$scope.newuser.password+"&email="+$scope.newuser.email+"&address="+$scope.newuser.address);
       //console.log(baseURL + "tag=register&fullName="+$scope.newuser.fullName+"&userName="+$scope.newuser.userName+"&password="+$scope.newuser.password+"&email="+$scope.newuser.email+"&address="+$scope.newuser.address);
        $http.post(baseURL + "tag=register&fullName="+$scope.newuser.fullName+"&userName="+$scope.newuser.userName+"&password="+$scope.newuser.password+"&email="+$scope.newuser.email+"&address="+$scope.newuser.address+"").then(function (res){
           
            debugger;
             console.log(res);
            $ionicLoading.hide();
            $scope.response = res.data;
            console.log($scope.response);
            debugger;
           if($scope.response.error == true)
            {
                if($scope.response.error_msg =="User already existed")
                {
                    var errorMsg = "User already existed.Try with new email ID!";
                    $ionicPopup.alert({
                        title: 'Alert',
                        template: errorMsg
                    });
                    $state.go("login");
                }
                 else if($scope.response.error_msg =="Error occured in Registration")
                {
                    var errorMsg = "Error occured in Registration!";
                    $ionicPopup.alert({
                        title: 'Alert',
                        template: errorMsg
                    });
                    $state.go("login");
                }
            } else{
                debugger;
                 var errorMsg = "Registration done successfully!";
                    $ionicPopup.alert({
                        title: 'Alert',
                        template: errorMsg
                    });
                  //  console.log(document.getElementById("FileToUpload").value);
                    document.getElementById("imageForm").submit();
                   debugger;
                   //console.log($cordovaFileTransfer);
                   //uploadImage();
                  
                    $state.go("login");
            }
        }); 
}
else {
        $scope.showMsgs = true;
        var errorMsg = "Please fill mandetary * feilds !";
            $ionicPopup.alert({
                title: 'Alert',
                template: errorMsg
            });
            }
    };

$scope.newusercrt1 = function(form){
    debugger;
    $scope.showMsgs = false;
    if (form.$valid) {
        } else {
            $scope.showMsgs = true;
                var errorMsg = "Please fill mandetary * feilds !";
                    $ionicPopup.alert({
                        title: 'Alert',
                        template: errorMsg
                    });
        }
}

function uploadImage() {
    console.log($cordovaFileTransfer);
    // Destination URL
    var url = "http://localhost/carvicewebservice/test.php";
   
    // File for Upload
   // var targetPath = $scope.pathForImage($scope.image);
   var targetPath = "";
    // File name only
    var filename = "vijaya";
   
    var options = {
      fileKey: "file",
      fileName: filename,
      chunkedMode: false,
      mimeType: "multipart/form-data",
      params : {'fileName': filename}
    };
   
    $cordovaFileTransfer.upload(url, targetPath, options).then(function(result) {
      $scope.showAlert('Success', 'Image upload finished.');
    });
  }

});
